package com.lcn.rabbitmq;

import org.springframework.amqp.core.*;
import org.springframework.beans.factory.annotation.Qualifier;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;

@Configuration
public class ChatMsgMQConfig {

    public static final String CHAT_MSG_EXCHANGE = "chat_msg_exchange";

    public static final String CHAT_MSG_QUEUE = "chat_msg_queue";

    public static final String CHAT_MSG_ROUTING_KEY = "com.lcn.chat.msg";

    @Bean(CHAT_MSG_EXCHANGE)
    public Exchange exchange() {
        return ExchangeBuilder.topicExchange(CHAT_MSG_EXCHANGE).durable(true).build();
    }

    @Bean(CHAT_MSG_QUEUE)
    public Queue queue() {
        return QueueBuilder.durable(CHAT_MSG_QUEUE).build();
    }

    @Bean
    public Binding binding(@Qualifier(CHAT_MSG_EXCHANGE) Exchange exchange, @Qualifier(CHAT_MSG_QUEUE) Queue queue) {
        return BindingBuilder.bind(queue).to(exchange).with("com.lcn.#").noargs();
    }

}
